import axios from "axios";
import { get, post } from "@/request";

/* 获取推荐歌单 */
export const getPersonalized = () => get("playList/recommend");

/* login 获取个性推荐歌单 */
export const getRecommend = () => get("playList/resource");

/* 创建歌单 */
export const postCreatePlayList = (title,isPublic) =>
  axios.post(
    "/playList/createplaylist",
    { title: title,isPublic:isPublic+"" },
    {
      headers: {
        Authorization: localStorage.getItem("token"),
      },
    }
  );

/* 获取歌单详情 */
export const getPlayListDetail = (uuid,id) => get("/playList/detail", { uuid,id });

/* login 更新歌单信息 */
export const updateMyPlayList = ({ id, name, desc, tags }) =>
  post("/playList/update", { listId:id, name, description:desc, tagStr:tags });//这里我对应了一下后端的实体字段！

/* login 添加/删除歌曲到自己创建的歌单 op:del/add pid:playlistId  tracks:musicId 用逗号隔开的字符串*/
export const MusicToPlaylist = ({ op, pid, tracks }) =>
  get("/playlist/tracks", { op, pid, tracks });

/* 上传歌单封面 */
export const uploadPlayListImg = (formData) =>
  axios.post(`/playList/coverupload`, formData, {
    "Content-Type": "multipart/form-data",
  });

/* 删除歌单 */
export const deletePlayList = ({ id, token }) =>
  axios.get(`/playList/delplayList?id=${id}`, {
    headers: {
      Authorization: token,
    },
  });

/* 添加歌曲至歌单 */

export const addSongToPlayList = ({ musicId, playlistId }) =>
  get(`/playList/tracksAdd`, { musicId, playlistId });

/* 删除歌单中的歌曲 */

export const deleteMusicFromList = ({ musicId, playId, token }) =>
  axios.get(`/playList/delsongInp?musicId=${musicId}&playId=${playId}`, {
    headers: {
      Authorization: token,
    },
  });

  /**
   * 由于开发时间期限的问题，我们在这下面考虑安全编程的问题会相对减少
   * 后面肯定会涉及一系列的问题。
  */

/* 获取歌单评论 */
export const getAllComment = (uuid,listId) => get("/playList/getAllComment",{uuid,listId});

/* 在具体歌单下增加一条记录 */
export const addComment = (uuid,message,listId) => get("/playList/addComment",{uuid,message,listId});

/* 回复操作 */
export const addReply =(message, uuid, listId, lastId)=>get("/playList/addReply",{message, uuid, listId, lastId})

/* 删除评论或者回复 */
/* TODO:这里本来就是只能删除自己的评论，有个问题，可能会产生一个安全问题 ,那就是可能会删除歌单发布者的评论*/
export const delComment = (id) => get("/playList/delComment",{id});

/* 点赞o(￣▽￣)ｄ */
export const support = (id,isSupport,uuid) => get("/playList/support",{id,isSupport,uuid});

/* 获取其他用户信息详情 */
export const getCommentUserInfo=(uuid)=>get("/playList/getCommentOrPlayListUserInfo",{uuid});

/* 公开歌单的收藏 */
export const addFavorites = (uuid,listid) => get("/playList/addFavorites",{uuid,listid});

/* 公开歌单取消收藏 */
export const removeFavorites = (uuid,listid) => get("/playList/removeFavorites",{uuid,listid});

/* 获取所有收藏 */
export const getUserFavorites = (uuid) => get("/playList/getUserFavorites",{uuid});